/* 排序
* 
* 本题:
    最优解一定断环成链

*/

#define DEBUG
#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define int long long
const int N = 1e5+10;
int row[N], col[N], s[N], c[N];

int work(int n, int a[])
{
    for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i]; //处理前缀和

    if(s[n]%n) return -1;

    int avg = s[n]/n;

    c[1] = 0;
    for(int i = 2; i <= n; i++) c[i] = s[i-1] - (i-1) * avg;//当前行的需求量 +给出-拿入

    sort(c+1, c+n+1);
    int res = 0;
    for(int i = 1; i <= n; i++) res += abs(c[i]-c[(n+1)/2]);
    return res;
}

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
    #else
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #endif
    
    int n, m, cnt;
    cin >> n >> m >> cnt;

    while(cnt--)
    {
        int x, y; cin >> x >> y;
        row[x]++, col[y]++;
    }

    int r = work(n, row);
    int c = work(m, col);

    if(r != -1 && c != -1) printf("both %lld\n", r + c);
    else if (r != -1) printf("row %lld\n", r);
    else if (c != -1) printf("column %lld\n", c);
    else printf("impossible\n");

    return 0;
}